import java.io.BufferedReader;
import java.io.PrintStream;
import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworks
 * Date: 8/25/13
 * Time: 2:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class Score {
    String score = "0/0";
    int player1Score = 0;
    int player2Score = 0;
    LinkedList<String> scores;
    PrintStream printStream;
    BufferedReader bufferedReader;

    public Score(PrintStream printStream, BufferedReader bufferedReader) {
        this.printStream = printStream;
        this.bufferedReader = bufferedReader;
        scores = new LinkedList<String>();
        scores.add("0");
        scores.add("15");
        scores.add("30");
        scores.add("40");
    }

    public String getScore() {
        return this.score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public void increaseScore(String playerNumber) {
        boolean hasWinner = checkForWinner(playerNumber);
        if (!hasWinner)               {
            if (playerNumber.equals("1"))   {
                player1Score += determineIncrease(player1Score);
            }
            else {
                player2Score += determineIncrease(player2Score);
            }
            this.score = player1Score + "/" + player2Score;
            printStream.println(this.score);
        }
    }


    public int determineIncrease(int score) {
        return Integer.parseInt(scores.get(score +1));
    }

    public boolean checkForWinner(String playerNumber) {
        if (playerNumber.equals("1") && player1Score == 40) {
            printStream.println("Player 1 Wins!");
            return true;
        }
        else if (playerNumber.equals("2") && player2Score == 40) {
            printStream.println("Player 2 Wins!");
            return true;
        }
        return false;
    }
}
